package me.zk.practice1.hw;

import java.util.*;

/**
 * @author zhangkai
 * @date 2023/8/8 17:27
 */
public class HWBJ30 {
    //4,5
    //10,6,9,7,6
    //9,10,6,7,5
    //8,10,6,5,10
    //9,10,8,4,9
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.nextLine();
        String[] s2 = s1.split(",");
        //p w
        int m = Integer.parseInt(s2[0]);

        int n = Integer.parseInt(s2[1]);

        if (m < 3 || m >10 || n<3||n >100) {
            System.out.println(-1);
        }
        List<Player> list = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            Player p = new Player();
            p.id = i+1;
            p.s = new int[10];
            list.add(p);
        }

        for (int i = 0; i < m; i++) {
            String s = scanner.nextLine();

            int[] nums = Arrays.stream(s.split(",")).mapToInt(Integer::parseInt).toArray();

            for (int j = 0; j < n; j++) {
                int score = nums[j];
                if (score < 1 || score > 10) {
                    System.exit(1);
                }
                Player p = list.get(j);
                p.s[10-score]++;
                p.total+=score;
            }
        }
       Collections.sort(list);
        String res = "";
        for (int i = 0; i < 3; i++) {
            res+=list.get(i).id;
            if (i !=2) {
                res+=",";
            }
        }
        System.out.println(res);
    }

    static class Player implements Comparable<Player> {
        int id;
        int[] s;
        int total;


        @Override
        public int compareTo(Player o) {
            if (o.total == this.total) {
                for (int i = 0; i < 10; i++) {
                  if (this.s[i] == o.s[i]){
                      continue;
                  }
                  return o.s[i]-this.s[i];
                }
            }
            return o.total - this.total;
        }
    }
}
